var express = require('express');
var router = express.Router();

// middleware that is specific to this router
router.use(function timeLog (req, res, next) {
  console.log('Time: ', Date.now());
  res.set({
    "Access-Control-Allow-Origin": "*",
    "Access-Control-Allow-Methods": "PUT,POST,GET,DELETE,OPTIONS",
    "Access-Control-Allow-Headers": "Content-Type",
    "Content-Type": "application/json; charset=utf-8",
  })
  next();
});

// define the home page route
router
  .get('/', function (req, res) {
    res.send({ a: 'Birds home page' });
  })
  .get('/order', (req, res, next) => {
    res.send({
      code: "0000",
      msg: "成功",
      data: {
        other: "hellow this night!",
        list: [
          {
            name: "wsz",
            sex: "man",
            age: 23
          },
          {
            name: "hm",
            sex: "wman",
            age: 22
          }
        ]
      }
    })
  });
// define the about route
router.post('/about', function (req, res) {
    res.send({ go: 'About birds' });
  })
  .post('/local/hello', function (req, res) {
    res.send({
      code: "0000",
      msg: "成功",
      data: {
        other: "hellow this night!",
        list: [
          {
            name: "wsz",
            sex: "man",
            age: 23
          },
          {
            name: "hm",
            sex: "wman",
            age: 22
          }
        ]
      }
    });
  })

module.exports = router;
